package com.atguigu.MyTest;

import org.junit.jupiter.api.Test;

import java.util.Scanner;

/**
 * @author haoranlu
 * @project IntelliJ IDEA
 */
public class TestUserDAOImp1 {
    @Test
    public void test01(){
        UserDAO ud = new UserDAOImp1();
        Scanner input = new Scanner(System.in);

        System.out.println("----登录----");
        System.out.print("用户名：");
        String username = input.nextLine();

        System.out.print("密码：");
        String password = input.nextLine();

        User user = new User(username,password);
        User user1 = ud.getUser(user);
        if(user1 == null){
            System.out.println("登录失败，用户名或密码错误");
        }else{
            System.out.println("登录成功：" + user1);
        }

        input.close();
    }

    public static void main(String[] args) {
        UserDAO ud = new UserDAOImp1();
        Scanner input = new Scanner(System.in);

        System.out.println("----注册----");
        String username;
        while(true){
            System.out.print("用户名：");
            username = input.nextLine();

            if(ud.checkUserName(username)==false){
                break;
            }else{
                System.out.println("用户名已存在，请重写输入");
            }
        }

        System.out.print("密码：");
        String password = input.nextLine();

        System.out.print("邮箱：");
        String email = input.nextLine();

        try {
            User user = new User(username,password,email);
            ud.SaveUser(user);
            System.out.println("注册成功");
        } catch (Exception e) {
            System.out.println("注册失败，原因：" + e.getMessage());
        }

        input.close();
    }
}
